package com.miguo.framework.utils;

public class Log {

    /* DEBUG状态 true false */
    public static boolean DEBUG = false;

    private static String className;
    private static String methodName;
    private static int lineNumber;

    private static String createLog(String log) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("[");
        buffer.append(methodName);
        buffer.append(":");
        buffer.append(lineNumber);
        buffer.append("]");
        buffer.append(log);
        return buffer.toString();
    }

    private static void getMethodNames(StackTraceElement[] sElements) {
        className = sElements[1].getFileName();
        methodName = sElements[1].getMethodName();
        lineNumber = sElements[1].getLineNumber();
    }

    public static void e(String message) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.e(className, createLog(message));
    }

    public static void e(String message, Object... args) {
        if (!DEBUG) {
            return;
        }

        if (args.length > 0) {
            message = String.format(message, args);
        }
        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.e(className, createLog(message));
    }

    public static void e(String message, Throwable throwable) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.e(className, createLog(message), throwable);
    }

    public static void i(String message) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.i(className, createLog(message));
    }

    public static void i(String message, Object... args) {
        if (!DEBUG) {
            return;
        }

        if (args.length > 0) {
            message = String.format(message, args);
        }
        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.i(className, createLog(message));
    }

    public static void i(String message, Throwable throwable) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.i(className, createLog(message), throwable);
    }

    public static void d(String message) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.d(className, createLog(message));
    }

    public static void d(String message, Object... args) {
        if (!DEBUG) {
            return;
        }

        if (args.length > 0) {
            message = String.format(message, args);
        }
        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.d(className, createLog(message));
    }

    public static void d(String message, Throwable throwable) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.d(className, createLog(message), throwable);
    }

    public static void v(String message) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.v(className, createLog(message));
    }

    public static void v(String message, Object... args) {
        if (!DEBUG) {
            return;
        }

        if (args.length > 0) {
            message = String.format(message, args);
        }
        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.v(className, createLog(message));
    }

    public static void v(String message, Throwable throwable) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.v(className, createLog(message), throwable);
    }

    public static void w(String message) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.w(className, createLog(message));
    }

    public static void w(String message, Object... args) {
        if (!DEBUG) {
            return;
        }

        if (args.length > 0) {
            message = String.format(message, args);
        }
        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.w(className, createLog(message));
    }

    public static void w(String message, Throwable throwable) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.w(className, createLog(message), throwable);
    }

    public static void wtf(String message) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.wtf(className, createLog(message));
    }

    public static void wtf(String message, Object... args) {
        if (!DEBUG) {
            return;
        }

        if (args.length > 0) {
            message = String.format(message, args);
        }
        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.wtf(className, createLog(message));
    }

    public static void wtf(String message, Throwable throwable) {
        if (!DEBUG) {
            return;
        }

        getMethodNames(new Throwable().getStackTrace());
        android.util.Log.wtf(className, createLog(message), throwable);
    }
}
